﻿//-----------------------------------------------------------------------
// <copyright file="DomainUnityRegistration.cs" company="deixei.com">
//     Copyright (c) deixei.com. All rights reserved.
// </copyright>
// <author>Marcio Parente</author>
//---------------------------------------------------------------------
namespace Deixei.Domain
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Deixei.Domain.Repository;
    using Deixei.Domain.Service;
    using Deixei.Infrastructure;
    using Microsoft.Practices.ServiceLocation;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.InterceptionExtension;

    public static class DomainUnityRegistration
    {
        public static void Registration()
        {
            //// Global
            DeixeiContainer.Container.RegisterInstance<DataContext>(new DataContext()).AddNewExtension<Interception>();
            DeixeiContainer.Container.RegisterType<IUnitOfWork, UnitOfWork>(new ContainerControlledLifetimeManager());
            //// Repository
            DeixeiContainer.Container.RegisterType<IActionLogRepository, ActionLogRepository>().AddNewExtension<Interception>();
            DeixeiContainer.Container.RegisterType<ICustomerRepository, CustomerRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IIngredientRepository, IngredientRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<INavigationAreaRepository, NavigationAreaRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<INavigationControllerRepository, NavigationControllerRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IOrderRepository, OrderRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IOrderTypeRepository, OrderTypeRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IPersonRepository, PersonRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IProductRepository, ProductRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IRoleRepository, RoleRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<ISupplierRepository, SupplierRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IUserRepository, UserRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IVendorRepository, VendorRepository>(new ContainerControlledLifetimeManager());
            DeixeiContainer.Container.RegisterType<IWebAppPortfolioRepository, WebAppPortfolioRepository>(new ContainerControlledLifetimeManager());

            //// Services
            DeixeiContainer.Container.RegisterType<ICustomerService, CustomerService>(new InjectionConstructor(
                DeixeiContainer.Locator.GetInstance<ICustomerRepository>(), 
                DeixeiContainer.Locator.GetInstance<IOrderRepository>(), 
                DeixeiContainer.Locator.GetInstance<IUnitOfWork>()));
            
            DeixeiContainer.Container.RegisterType<INavigationService, NavigationService>(new InjectionConstructor(
                DeixeiContainer.Locator.GetInstance<IWebAppPortfolioRepository>(),
                DeixeiContainer.Locator.GetInstance<INavigationAreaRepository>(),
                DeixeiContainer.Locator.GetInstance<INavigationControllerRepository>(),
                DeixeiContainer.Locator.GetInstance<IUnitOfWork>()));
            //AuthorizationService :: IUnitOfWork IWebAppPortfolioRepository IUserRepository IRoleRepository 
            DeixeiContainer.Container.RegisterType<IAuthorizationService, AuthorizationService>(new InjectionConstructor(
                DeixeiContainer.Locator.GetInstance<IUnitOfWork>(),
                DeixeiContainer.Locator.GetInstance<IWebAppPortfolioRepository>(),
                DeixeiContainer.Locator.GetInstance<IUserRepository>(),
                DeixeiContainer.Locator.GetInstance<IRoleRepository>()));

        
        }
    }
}
